import React, { Component } from 'react'
import { connect } from 'react-redux';
import { BrowserRouter as Router, Redirect, Route, NavLink, Switch } from 'react-router-dom';
import './my.css'

class Login extends Component{
	constructor(props) {
	    super(props);
	}
	render(props) {
		return (
			
			<div style={{textAlign:""}} id='login-box'>,
				<div id='login-bijian'>笔尖</div>
				<div> 开启文字之旅</div>
				<div style={{height:'60px'}}> &nbsp; </div>,
				
				<div style={{margin:'20px'}}><input type="text" id="nicheng" placeholder="昵称" style={{height:'40px', width:'300px', border:'2px solid #73C1F3', borderRadius:'10px'}}/></div>
				<div style={{margin:'20px'}}><input type="password" id="mima" placeholder="请输入登录密码" style={{height:'40px', width:'300px', border:'2px solid #73C1F3', borderRadius:'10px'}}/></div>
				<div><button style={{height:'30px', width:'300px', backgroundColor:'#73C1F3', borderRadius:'10px'}} 
					onClick={() => {
						var nicheng = document.getElementById('nicheng').value;
						//console.log(nicheng);
						var mima = document.getElementById('mima').value
						//console.log(mima);
						if(nicheng != '' && mima != '')
						fetch('http://62.234.30.197:8088/userlist/chaid', {
							method: 'post',
							body: JSON.stringify({'name':`${nicheng}`}),
							headers: {
							    "Access-Control-Allow-Origin":"*",
							    'content-type': 'application/json'
							},
							mode: 'cors'
						})
						.then(res=>res.json())
						.then(res=> {
							if(mima === res[0].password) {
								localStorage.setItem("userid",res[0].userid);
								//console.log(localStorage.getItem("userid"));
								this.props.history.push('/Home');
							}
							else {
								alert('密码错误！');
								//window.location.reload(true)
							}
						})
						
					}} >登录</button><br /><br />
					
				<button style={{height:'30px', width:'300px', backgroundColor:'#73C1F3', borderRadius:'10px'}} 
					onClick={() => {
						this.props.history.push('/Zhuce')
					}} >立即注册</button>
				</div>
			</div>
		)
	}
}


//export default connect(null, { login })(Login)
export default Login;